<?php
/*
 * 太平洋汽车导购
 * 检查表
 *      xd_xxx,
 *      xd_xxx_data
 *      xx/201307/31/
 *      xxx/SpiderResult.db3
 * @package    system
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: e4f07ecf02fc7975c7a545205f7edb9c5006cfe2 $
 */
set_time_limit(0);
include '../../common.inc.php';
include '137.common.php';

$hd = new ImportLoop();
$hd->setAim('mysql:host=192.168.1.19;dbname=ixdcw_v11', 'root', 'xddlxdcw');
//$hd->setSource('sqlite:d:/LocoySpider_V7.6_Build20121106.Free/Data/LocoySpider/137/SpiderResult.db3', '', '');
$hd->setSource('sqlite:d:/chekuan2/SpiderResult.db3', '', '');
$hd->setSourceInfo('content', 'id', ' 已发=1');
$params = array(
	'maxid'     => isset($_GET['maxid']) ? $_GET['maxid'] : 0,
	'id'        => isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : 0,
	'startTime' => isset($_GET['startTime']) ? $_GET['startTime'] : time(),
	'limit'     => 9000,
	'interval'  => 4,
	'debug'     => '',
	'moduleid'  => 23, // 资讯 26 导购23
	'catid'     => 0, // 3592 试驾体验   3593 新车图解    3594   购车手册    3595  车型对比
	'picAdd'    => 'http://www.pcauto.com.cn/',
	'siteName'  => '太平洋汽车导购',
	'userid'    => '1',
	'username'  => 'xddlmaster', // id
	'timeType'  => 5,
);

$fields = array(
	'time'     => 'time', // 时间字段
	'title'    => 'title', // 标题字段
	'id'       => 'ID', // id
	'copyfrom' => 'comefrom', // from
);

$hd->initParams($params);
$sql = 'select * from ' . $hd->getSourceTable() . ' where id>' . $hd->getParam('id') . ' order by id ASC limit ' . $hd->getParam('limit');
$result = $hd->getDbSource()->query($sql);
$rs     = $result->fetchAll();

if (!$rs) {
	$hd->times();
	$hd->end();
} else {
	foreach($rs as $key=>$value){
//初始化数据
		$config=json_decode($value["config"]);
		$option=json_decode($value["option"]);
		$color=json_decode($value["color"]);
		$dealerPrices=json_decode($value["dealerPrices"]);
		foreach($config->result->paramtypeitems as $k=>$v){
			//echo '----'.$v->name.'<br/>';
			if($v->name=='发动机'){
				foreach($v->paramitems as $k2=>$v2){
					//echo $v2->name.'<br/>';
					if($v2->name=='进气形式'){
						foreach($v2->valueitems as $k3=>$v3){
							$air[$v3->value]=1;
						}
					}
				}
			}
		}
		/*
		foreach($option->result->configtypeitems as $k=>$v){

			if($v->name=='玻璃/后视镜'){
				foreach($v->configitems as $k2=>$v2){
					//echo $v2->name.'<br/>';
					if($v2->name=='前桥限滑差速器/差速锁'){
						foreach($v2->valueitems as $k3=>$v3){
							$air[$v3->value]=1;
						}
					}
				}
			}
		}
		*/
		//颜色 轮询输入
/*
		if($color->result->specitems){
			foreach($color->result->specitems as $k=>$v){
				echo '----'.$v->specid;
				foreach($v->coloritems as $k2=>$v2){
					echo $v2->name.'<br/>';
				}
			}
		}
*/
		/*
		foreach($option->result->configtypeitems as $k=>$v){
			echo '----'.$v->name.'<br/>';
			foreach($v->configitems as $k2=>$v2){
				//echo $v2->name.'<br/>';
				foreach($v2->valueitems as $k3=>$v3){
					$v3->specid='';
					$v3->value='';
				}
			}
		}
		*/
	}
}

$hd->setSource('sqlite:d:/chexi/SpiderResult.db3', '', '');
$hd->setSourceInfo('content', 'id', ' 已发=1');
$hd->initParams($params);
$sql = 'select * from ' . $hd->getSourceTable() . ' where id>' . $hd->getParam('id') . ' order by id ASC limit ' . $hd->getParam('limit');
$result = $hd->getDbSource()->query($sql);
$rs     = $result->fetchAll();

if (!$rs) {
	$hd->times();
	$hd->end();
} else {
	foreach($rs as $key=>$value){
//初始化数据
		$config=json_decode($value["config"]);
		$option=json_decode($value["option"]);
		$color=json_decode($value["color"]);
		$dealerPrices=json_decode($value["dealerPrices"]);
		$sqlUpdate = Sql::update($hd->getSourceTable(), ' ', "id={$value[$fields['id']]}");
		foreach($config->result->paramtypeitems as $k=>$v){
			//echo '----'.$v->name.'<br/>';
			if($v->name=='发动机'){
				foreach($v->paramitems as $k2=>$v2){
					//echo $v2->name.'<br/>';
					if($v2->name=='进气形式'){
						foreach($v2->valueitems as $k3=>$v3){
							$air[$v3->value]=1;
						}
					}
				}
			}
		}
		/*
		foreach($option->result->configtypeitems as $k=>$v){

			if($v->name=='玻璃/后视镜'){
				foreach($v->configitems as $k2=>$v2){
					//echo $v2->name.'<br/>';
					if($v2->name=='前桥限滑差速器/差速锁'){
						foreach($v2->valueitems as $k3=>$v3){
							$air[$v3->value]=1;
						}
					}
				}
			}
		}
		*/
		//颜色 轮询输入
		/*
				if($color->result->specitems){
					foreach($color->result->specitems as $k=>$v){
						echo '----'.$v->specid;
						foreach($v->coloritems as $k2=>$v2){
							echo $v2->name.'<br/>';
						}
					}
				}
		*/
		/*
		foreach($option->result->configtypeitems as $k=>$v){
			echo '----'.$v->name.'<br/>';
			foreach($v->configitems as $k2=>$v2){
				//echo $v2->name.'<br/>';
				foreach($v2->valueitems as $k3=>$v3){
					$v3->specid='';
					$v3->value='';
				}
			}
		}
		*/
	}
}
	var_dump($air);

function set_xd_auto_model($xd_auto_model){
	if(!$xd_auto_model){
		$xd_auto_model=array(
			'amid' => 0,
			'arbid' => 0,
			'armid' => 0,
			'arcid' => 0,
			'acid' => 0,
			'name' => '',
			'price' => 0,
			'enginetype' => 0,
			'emission' => 0,
			'gearbox' => 0,
			'country' => 0,
			'year' => 0,
			'issale' => 1,//在售都设置为 1 在售
			'linkurl' => '',//为空
			'attention' => 0,//关注度
			'addtime' => 0,//时间
			'edittime' => 0,//时间
			'username' => 'xddlmaster',//添加者
			'attentiontime' => 0,//关注度时间
			'model_thumb' => '',//为空
			'modeltype' => 'passenger',//车型
			'listorder' => 0,//排序
			'status' => 0,//数据存放到 回收站
	    );
	}
	return $xd_auto_model;
}
function set_xd_auto_model_passenger($xd_auto_model_passenger){
	if(!$xd_auto_model_passenger){
		$xd_auto_model_passenger=array(
			'amid' => 0,
			'length' => 0,
			'width' => 0,
			'height' => 0,
			'front_track' => 0,
			'rear_track' => 0,
			'wheelbase' => 0,
			'ground_clearance' => 0,
			'turning_radius' => 0,//最小转弯直径 汽车之家无此参数
			'curb_weight' => 0,
			'car_body_structure' => 0,
			'roof_opan_way' => 0,//车篷开合方式 汽车之家无此参数
			'doors_num' => 0,
			'seats_num' => 0,
			'approach_angle' => 0,//接近角(°) 汽车之家无此参数
			'departure_angle' => 0,//离去角(°)
			'drag_coefficient' => 0,//风阻系数(Cd)
			'fording_depth' => 0,//最大涉水深度(m)
			'tank_capacity' => 0,
			'compartment_volume' => 0,
			'air_displacement' => '',
			'working_way' => 0,
			'cylinder_form' => 0,
			'cylinder_num' => 0,
			'valves_num' => 0,
			'compression_ratio' => 0,
			'valve_type' => 0,
			'engine_power' => 0,
			'power_motor' => 0,
			'gross_power' => 0,//汽车之家无此参数
			'acrot_orque' => 0,
			'power_acrot_orque' => 0,
			'torquemoment' => '',
			'model_num' => 0,//汽车之家无此参数
			'authoritative_techniques' => '',
			'cylinder_head' => 0,
			'cylinder_body' => 0,
			'fuel_num' => 0,
			'fuel_system' => '',
			'oil_wear' => 0,//汽车之家无此参数
			'gongkuang' => 0,
			'wangyou' => 0,
			'maximum_speed' => 0,
			'acceleration_time' => 0,
			'gear_num' => 0,
			'transmission_type' => 0,
			'rear_axle_differential' => '',
			'front_axle_differential' => '',
			'drive_type' => 0,
			'forward_mounting' => 0,
			'behind_mounting' => 0,
			'front_brake' => 0,
			'rear_brake' => 0,
			'power_steering' => 0,
			'front_type' => '',
			'rear_type' => '',
			'aluminium_hub' => 0,
			'spare_wheel' => 0,
			'main_air_bag' => 0,
			'copilot_air_bag' => 0,
			'front_side_air_bag' => 0,
			'rear_side_air_bag' => 0,
			'gas_proof_curtain' => 0,
			'lap_air_bag' => 0,
			'air_bag_num' => 0,//气囊(帘)个数(个)  汽车之家无此参数
			'camera' => 0,
			'side_aide' => 0,
			'panoramic_shooting' => 0,
			'seat_belt_hint' => 0,
			'electronic_theft' => 0,
			'control_center' => 0,
			'remote_control' => 0,
			'nokey_start' => 0,
			'nokey_unlock' => 0,
			'zero_voltage' => 0,
			'tire_pressure_monitoring' => 0,
			'auto_parking' => 0,
			'other_safe_deploy' => 0,//安全类特色配置  汽车之家无此参数
			'abs' => 0,
			'ebd' => 0,
			'tcs' => 0,
			'esp' => 0,
			'eba' => 0,
			'constant_speed' => 0,
			'acc' => 0,
			'eds' => 0,//EDS/EDL)电子差速制  汽车之家无此参数
			'initiative_control' => 0,
			'manual_brake' => 0,
			'auto_parking_brake' => 0,
			'hac' => 0,
			'hdc' => 0,
			'body_height_adjustable' => 0,
			'air_suspension' => 0,
			'active_steering' => 0,
			'control_setting' => '',//操控类特色配置   汽车之家无此参数
			'skylight' => 0,
			'luggage_compartment_auto' => 0,
			'induction_wiper' => 0,
			'queen_wiper' => 0,
			'body_color' => '',
			'cortex_steering_wheel' => 0,
			'multi_function_steering_wheel' => 0,
			'steering_wheel_stage_changeover' => 0,
			'steering_wheel_regulate' => 0,
			'outside_temperature' => 0,
			'oil_wear_dispaly' => 0,
			'hud' => 0,
			'night_vision' => 0,
			'rear_guard_abat_vent' => 0,
			'rear_front_screen_abat_vent' => 0,
			'headlight' => 1, //默认前头灯为 卤素灯
			'front_fog_lamp' => 0,
			'headlight_depth_control' => 0,
			'headlight_clear' => 0,
			'outside_light_auto_close' => 0,
			'auto_headlight' => 0,
			'afs' => 0,
			'daytime_lamp' => 0,
			'front_power_window' => 0,
			'rear_power_window' => 0,
			'window_antitrapping' => 0,
			'one_key_window' => 0,
			'exterior_mirror_control' => 0,
			'exterior_mirror_heating' => 0,
			'exterior_mirror_power_pucker' => 0,
			'inside_mirror_auto_glitz' => 0,
			'manually_air_conditioner' => 0,
			'auto_air_conditioner' => 0,
			'temperature_division' => 0,
			'backseat_air_outlet' => 0,
			'filter' => 0,
			'refrigerating_alone' => 0,
			'icebox' => 0,
			'cortex_seats' => 0,
			'admixture_seats' => 0,
			'sport_seats' => 0,
			'seats_regulate' => 0,
			'copilot_seats_regulate' => 0,
			'seats_height_regulate' => 0,
			'lumbar_support_regulate' => 0,
			'fall_ratio' => 0,
			'second_row_regulate' => 0,
			'third_row_regulate' => 0,
			'isofix' => 0,
			'electric_seat_memory' => 0,
			'seat_massage' => 0,
			'seat_airy' => 0,
			'seat_heating' => 0,
			'second_row_heating' => 0,
			'front_seat_arm' => 0,
			'rear_seat_arm' => 0,
			'single_dish_cd' => 0,
			'multidisc_cd' => 0,
			'single_dish_dvd' => 0,
			'multidisc_dvd' => 0,
			'mp3' => 0,
			'external_connection_sound' => 0,
			'speaker_num' => 0,
			'acoustics_brand' => '',
			'bluetooth' => 0,
			'gps' => 0,
			'tv' => 0,
			'rear_guard_lcd' => 0,
			'disk_multimedia' => 0,
			'man_machine' => 0,
			'szm_screen' => 0,
			'multimedia_setting' => '',
			'other_setting' => '',
			'air'=> '',
			'structure' => 0,
//			'price' => 0,
			'max_inner_height' => 0,
			'rpm' => 0
		);
	}
	return $xd_auto_model_passenger;
}
//echo $hd->start($hd->getParams());
function isHave($value,$list=0){
	if($list==0){
		if(strpos($value,"●")){
			//有
			$return=1;
		}else if(strpos($value,"○")){
			//选装
			$return=2;
		}else{
			//无讯息或无
			$return=0;
		}
	}else{
		$value=explode('/',$value);
		if(strpos($value[$list-1],"●")){
			//有
			$return=1;
		}else if(strpos($value[$list-1],"○")){
			//选装
			$return=2;
		}else{
			//无讯息或无
			$return=0;
		}
	}
	return $return;
}
function getParamCatid($catname) {
	switch ($catname) {
		case '深度调查':
		case '新车图解':
			return 3592;
			break;
		case '实拍图秀':
		case '国内新车':
		case '新车频道':
			return 3593;
			break;
		case '新车点评':
		case '选车心得':
		case '汽车导购':
		case '购车手册':
			return 3594;
			break;
		case '车型PK':
		case '初步海选':
		case '比较与推荐':
			return 3595;
			break;
	}
	return 0;
}